using System;
using System.Collections.Generic;
using System.Text;
using System.Drawing;
using System.Globalization;

namespace Svg.Pathing
{
    public sealed class SvgLineSegment : SvgPathSegment
    {
        public SvgLineSegment(PointF start, PointF end, bool isRelative)
        {
            this.Start = start;
            this.End = end;
            this.IsRelative = isRelative;
        }

        public override void AddToPath(System.Drawing.Drawing2D.GraphicsPath graphicsPath)
        {
            graphicsPath.AddLine(this.Start, this.End);
        }

        public string RenderSegmentToSvgString(string specifier, CultureInfo culture)
        {
            if (this.IsRelative)
            {
                string format = "l" + "{0}"
                            + Math.Round((this.End.X - this.Start.X),3).ToString(specifier, culture) + "{1}"
                            + Math.Round((this.End.Y - this.Start.Y),3).ToString(specifier, culture);
                return String.Format(format,
                    ((this.End.X - this.Start.X) == 0) ? "-" : String.Empty,
                    ((this.End.Y - this.Start.Y) == 0) ? "-" : ((this.End.Y - this.Start.Y) > 0) ? "," : String.Empty
                    );
            }
            else
            {
                return ("L" + Math.Round(this.End.X,3).ToString(specifier, culture) + ","
                                + Math.Round(this.End.Y,3).ToString(specifier, culture));
            }



        }
    }
}